$(function () {
    fy(1, 3);
})

function tb() {
    $(".table").append("  <tr>\n" +
        "        <th width=\"100\" style=\"text-align:left; padding-left:20px;\">ID</th>\n" +
        "        <th width=\"10%\">姓名</th>\n" +
        "        <th>照片</th>\n" +
        "        <th>身份证号</th>\n" +
        "        <th>性别</th>\n" +
        "        <th>教龄</th>\n" +
        "        <th>级别</th>\n" +
        "        <th width=\"10%\">累计销售</th>\n" +
        "        <th width=\"310\">操作</th>\n" +
        "      </tr>")
}

function fy(pageNum, pageSize) {
    $.post("/beyond/selectTeacher1", {"pageNum": pageNum, "pageSize": pageSize}, function (data) {
        $.each(data.list, function (i, cha) {
            var sex = cha.gender == 1 ? "女" : "男";
            $(".table").append(" <tr>\n" +
                "          <td style=\"text-align:left; padding-left:20px;\"><input type=\"checkbox\" name=\"id[]\" value=\"\" />\n" +
                "           " + (i + 1) + "</td>\n" +
                "          <td>" + cha.name + "</td>\n" +
                "          <td width=\"10%\"><a><img src=\"images/" + cha.filename + "\" alt=\"资格证号：111\" width=\"100\" height=\"100\" /></a></td>\n" +
                "          <td>" + cha.number + "</td>\n" +
                "          <td><font color=\"#00CC99\">" + sex + "</font></td>\n" +
                "          <td>" + cha.record + "</td>\n" +
                "          <td>" + cha.typename + "</td>\n" +
                "          <td>" + cha.sale + "</td>\n" +
                "          <td><div class=\"button-group\"> <a class=\"button border-main\" href=\"javascript:;\" data-id='" + cha.id + "'><span class=\"icon-edit\"></span>级别调整</a> <a class=\"button border-red\" href=\"javascript:;\" data-id='" + cha.id + "'><span class=\"icon-trash-o\"></span>解约</a> </div></td>\n" +
                "        </tr>")
        })
        $(".table").append(" <tr>\n" +
            "                <td colspan=\"9\"><div class=\"pagelist\"></div></td>\n" +
            "            </tr>")

        /*分页*/
        $(".pagelist").empty();
        if (data.pageNum > 1) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="1" >首页</a>')
        }
        if (data.pageNum - 1 >= 1) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + (data.pageNum - 1) + '" >上一页</a>')
        }
        $.each(data.navigatepageNums, function (index, fy) {
            if (data.pageNum == fy) {
                $(".pagelist").append(
                    "<a href=\"javascript:void(0)\" style='background-color: skyblue' class=\"curs\" id='" + fy + "'>" + fy + "</a>"
                )
            } else {
                $(".pagelist").append(
                    "<a href=\"javascript:void(0)\" class=\"curs\" id='" + fy + "'>" + fy + "</a>"
                )

            }

        })
        if (data.pageNum < data.pages) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + (data.pageNum + 1) + '" >下一页</a>')
        }
        if (data.pageNum < data.pages) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + data.pages + '" >末页</a>')
        }
        $(".curs").click(function () {
            $(".table").empty();
            tb();
            fy($(this).attr("id"), 3)
        })
        $(".button").click(function () {
            $(".panel").empty();
            var id = $(this).data("id");
            $.post("/beyond/selectByPrimaryKey", {"id": id}, function (data) {
                console.log(data)
                $(".panel").append(" <div class=\"panel-head\" id=\"add\"><strong><span class=\"icon-pencil-square-o\"></span>教师级别调整</strong></div>\n" +
                    "    <div class=\"body-content\">\n" +
                    "        <form method=\"post\" class=\"form-x\" action=\"\">\n" +
                    "            <input type=\"hidden\" name=\"id\" value=\"\"/>\n" +
                    "            <div class=\"form-group\">\n" +
                    "                <div class=\"label\">\n" +
                    "                    <label>教师姓名：</label>\n" +
                    "                </div>\n" +
                    "                <div class=\"field\">" +
                    "                  " + data.name + "  \n" +
                    "                    <div class=\"tips\"></div>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "            <div class=\"form-group\">\n" +
                    "                <div class=\"label\">\n" +
                    "                    <label>级别调整：</label>\n" +
                    "                </div>\n" +
                    "                <div class=\"field\">\n" +
                    "                    <select name=\"pid\" class=\"input w50\">\n" +
                    "                        <option value=\"1\">金牌讲师</option>\n" +
                    "                        <option value=\"2\">银牌讲师</option>\n" +
                    "                        <option value=\"3\">铜牌讲师</option>\n" +
                    "                        <option value=\"4\">废铁讲师</option>\n" +
                    "                    </select>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "            <div class=\"form-group\">\n" +
                    "                <div class=\"label\">\n" +
                    "                    <label></label>\n" +
                    "                </div>\n" +
                    "                <div class=\"field\">\n" +
                    "\n" +
                    "                    <button type=\"button\" onclick=\"addSubmit()\" class=\"button bg-main icon-check-square-o\">确认提交</button>\n" +
                    "                    <button type=\"button\" class=\"button bg-main icon-check-square-o\" onclick=\"fanhui()\">取消</button>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "        </form>\n" +
                    "    </div>")
                /*  localStorage.id=id;*/
                /*  location.href = "up.html"*/
                /* var pid = $(".input").val();
                 console.log(pid)*/
            })

        })

    })
}
